/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2020年8月30日
 */
package com.massyframework.beanskin.launcher.scanning;

import java.io.File;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 模块资源
 * @author huangkh
 *
 */
public class ModuleResources {
	
	private String groupId;
	private String moduleId;
	private String version;
	private Map<String, URL> resources;
	private File pomFile;

	/**
	 * 构造方法
	 * @param builder {@link Builder}
	 */
	protected ModuleResources(Builder builder) {
		this.resources = builder.resoruces == null ? Collections.emptyMap() : builder.resoruces;
		
		this.groupId = Objects.requireNonNull(builder.groupId, "\"groupId\" cannot be null.");
		this.moduleId = Objects.requireNonNull(builder.moduleId, "\"moduleId\" cannot be null.");
		this.version = Objects.requireNonNull(builder.version, "\"version\" cannot be null.");
		this.pomFile = builder.pomFile;
	}
	
	
	/**
	 * 组编号
	 * @return {@link String}
	 */
	public String getGroupId() {
		return this.groupId;
	}
	
	/**
	 * 模块编号
	 * @return {@link String}
	 */
	public String getModuleId() {
		return this.moduleId;
	}

	/**
	 * 模块版本
	 * @return {@link String}
	 */
	public String getVersion() {
		return version;
	}

	/**
	 * 资源
	 * @return {@link Map}
	 */
	public Map<String, URL> getResources() {
		return resources;
	}

	/**
	 * pom.xml文件
	 * @return {@link File}
	 */
	public File getPomFile() {
		return this.pomFile;
	}

	/**
	 * 创建构建器
	 * @return {@link Builder}
	 */
	public static Builder newBuilder() {
		return new Builder();
	}
	
	

	@Override
	public String toString() {
		return "ModuleResources [groupId=" + groupId + ", moduleId=" + moduleId + ", version=" + version
				+ ", resources=" + resources + ", pomFile=" + pomFile + "]";
	}



	/**
	 * 构建器
	 */
	public static class Builder {
		private String groupId;
		private String moduleId;
		private String version;
		
		private Map<String, URL> resoruces;
		private File pomFile;
				
		/**
		 * 组编号
		 * @param value {@link String}
		 * @return {@link Builder}
		 */
		public Builder groupId(String value) {
			this.groupId = value;
			return this;
		}
		
		/**
		 * 模块编号
		 * @param value {@link String}
		 * @return {@link Builder}
		 */
		public Builder moduleId(String value) {
			this.moduleId = value;
			return this;
		}
		
		/**
		 * 模块版本
		 * @param value {@link String}
		 * @return {@link Builder}
		 */
		public Builder version(String value) {
			this.version = value;
			return this;
		}
		
		/**
		 * 添加资源
		 * @param path {@link String}, 路经
		 * @param resource {@link URL}, 资源
		 * @return {@link Builder}
		 */
		public Builder addResource(String path, URL resource) {
			if (this.resoruces == null) {
				this.resoruces = new HashMap<String, URL>();
			}
			this.resoruces.put(path, resource);
			return this;
		}
		
		/**
		 * 设置pom.xml
		 * @param value {@link File}
		 * @return {@link Builder}
		 */
		public Builder pomFile(File value) {
			this.pomFile = value;
			return this;
		}
		
		public ModuleResources build() {
			return new ModuleResources(this);
		}
	}

}
